{extend name='../../admin/view/table'}

{block name="button"}


{/block}

{block name="content"}
<div class="think-box-shadow">

    <fieldset>


        <div class="layui-form-item layui-inline">
            <!-- {if auth('add')} -->
            <button class="layui-btn" data-title="添加优惠券" data-modal="{:url('add')}" type="button">
                <i class="layui-icon">&#xe61f;</i> 添 加
            </button>
            <!-- {/if} -->
        </div>

        </form>
    </fieldset>

    <table id="TagsData" data-url="{:sysuri()}" data-target-search="#TagsDataSearch"></table>
</div>
{/block}

{block name='script'}
<script>
    $(function () {
        $('#TagsData').layTable({
            even: true, height: 'full',
            sort: {field: 'id desc,id', type: 'desc'},
            cols: [[
                {field: 'id', title: 'ID', width: 80, align: 'center', sort: true},
                {field: 'coupon_name', title: '优惠券名称', minWidth: 100, align: 'center'},
                {field: 'satisfy_money', title: '满足多少钱', minWidth: 100, align: 'center' ,sort: true},
                {field: 'reduce_money', title: '减少多少钱', minWidth: 100, align: 'center' ,sort: true},
                {field: 'expire_time', title: '到期时间', minWidth: 170, align: 'center' ,sort: true},
                {field: 'total_number', title: '发行张数', minWidth: 100, align: 'center' ,sort: true},
                {field: 'surplus_number', title: '剩余张数', minWidth: 100, align: 'center' ,sort: true},
                {field: 'each_number', title: '每人最多领取几张', minWidth: 100, align: 'center'},
                {field: 'status', title: '状态', minWidth: 100, align: 'center', templet: '#StatusSwitchTpl'},
                {field: 'create_time', title: '创建时间', minWidth: 170, align: 'center',sort: true},
                {field: 'up_time', title: '修改时间', minWidth: 170, align: 'center',sort: true},
                {toolbar: '#ToolbarTagsData', title: '操作面板', minWidth: 100, align: 'center', fixed: 'right'},
            ]]
        });

        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (object) {
            object.data = {status: object.elem.checked > 0 ? 1 : 0};
            object.data.id = object.value.split('|')[object.data.status] || object.value;
            $.form.load("{:url('state')}", object.data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#FormTable').trigger('reload');
                }); else {
                    $('#FormTable').trigger('reload');
                }
                return false;
            }, false);
        });

    });
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-text="已激活|已禁用" lay-filter="StatusSwitch" lay-skin="switch" {{-d.status>0?'checked':''}}>
    <!--{else}-->
    {{-d.status ? '<b class="color-green">已激活</b>' : '<b class="color-red">已禁用</b>'}}
    <!--{/if}-->
</script>


<!-- 操控面板的模板 -->
<script type="text/html" id="ToolbarTagsData">

    <!--{if auth("edit")}-->
    <a class="layui-btn layui-btn-sm" data-title="编辑标签数据" data-modal='{:url("edit")}?id={{d.id}}'>编 辑</a>
    <!--{/if}-->

    <!--{if auth("remove")}-->
    <a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="确定要删除此优惠券吗？" data-action="{:url('remove')}" data-value="id#{{d.id}}">删 除</a>
    <!--{/if}-->
</script>
{/block}